package backend.service.admin;

import backend.model.admin.Project;
import backend.service.base.DBModelServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProjectServiceImpl extends DBModelServiceImpl<Project> implements ProjectService {

    @Override
    public Class<Project> getEntityClass() {
        return Project.class;
    }

    @Override
    public List<Project> findAllProjects() {
        return dbModelDao.findByNamedQuery("findAllProjects");
    }

    @Override
    public List<Project> findAllActiveProjects() {
        return dbModelDao.findByNamedQuery("findAllActiveProjects");
    }

    @Override
    public List<Project> findAllActiveAndDirectPaymentProjects() {
        return dbModelDao.findByNamedQuery("findAllActiveAndDirectPaymentProjects");
    }

    @Override
    public Project findProjectByName(String name) {
        List<Project> projectsByName = dbModelDao.findByNamedQueryAndParams("findProjectByName", new String[]{"name"}, new Object[]{name});
        assert projectsByName.size() <= 1;
        if (projectsByName.size() == 1) {
            return projectsByName.get(0);
        }
        return null;
    }

    @Override
    public List<Project> findDistinctProjectBookedForDate(Date date) {
        List<Project> result = dbModelDao.findByNamedQueryAndParams("findDistinctProjectBookedForDate",
                new String[]{"date"}, new Object[]{date});
        return result;
    }
}
